import java.net.*;

public class Message {
	private byte[] _data = null;			// the message content 
	private InetAddress _address = null;	// IP address
	private int _port;						// port
	private String _destPeerName = null;	// destination peer name
	
	/**
	 * Constructor
	 * @param data
	 * @param address
	 * @param port
	 * @param destPeerName
	 */
	public Message(byte[] data, InetAddress address, int port, String destPeerName) {
		_data = data;
		_address = address;
		_port = port;
		_destPeerName = destPeerName;
	}
	
	/**
	 * Constructor
	 * @param data
	 * @param address
	 * @param port
	 */
	public Message (byte[] data, InetAddress address, int port){
		_data = data;
		_address = address;
		_port = port;
		_destPeerName = null;
	}
	
	// get functions //
	public byte[] getData() {return _data;}
	
	public InetAddress getAddress() {return _address;}
	
	public int getPort() {return _port;}
	
	public String getDestPeerName() { return _destPeerName; }
	
	// set functions //
	public void setData(byte[] data){ _data = data; }
	
	/**
	 * equals function
	 */
	@Override
	public boolean equals(Object o){
		if (!(o instanceof Message))
			return false;
		
		Message msg = (Message)o;
		
		if (_data.equals(msg._data) && _address.equals(msg._address)
			&& _port == msg._port)
			return true;
		
		return false;
	}
	
	/**
	 * hashCode function.
	 */
	public int hashCode(){
		return (_data.hashCode()*31 + _address.hashCode()) * 31 + new Integer(_port).hashCode();
	}
}
